import React, { useContext, useEffect, useState } from 'react';
import { Button } from 'antd';
import styled from '@emotion/styled';
import { useStream } from '../Context/StreamContext';
import AgentService from '@/modules/Agent';
import { useTranslation } from 'react-i18next';
import { cancelInvitations } from '@/utils/lib';
import { IOperationName } from '@/modules/interface';

interface InstructionsProps {
	businessData?: any;
}

const InstructionsDiv = styled.div`
	width: auto;
	max-width: 100%;
	width: 100%;
	height: 36px;
	align-items: center;
	background: #3c6c9d;
	left: 50%;
	transform: translate(-50%, 0);
	bottom: 0px;
	display: flex;
	z-index: 30;
	padding: 0 10px;
	position: absolute;
`;

const InstructionsP = styled.p`
	white-space: nowrap;
	font-size: 10px;
	margin: 0;
	color: #ffffff;
	padding-right: 4px;
`;

const InstructionsButton = styled(Button)`
	width: 52px;
	height: 24px;
	border-radius: 4px;
	display: flex;
	align-items: center;
	justify-content: center;
	margin: 0 !important;
	font-size: 12px !important;
`;

const InstructionsSpan = styled.span`
	font-family: simsun;
	display: inline-block;
	width: 1.5em;
	vertical-align: bottom;
	overflow: hidden;
	animation: dot 3s infinite step-start;
	@keyframes dot {
		0% {
			width: 0;
			margin-right: 1.5em;
		}
		33% {
			width: 0.5em;
			margin-right: 1em;
		}
		66% {
			width: 1em;
			margin-right: 0.5em;
		}
		100% {
			width: 1.5em;
			margin-right: 0;
		}
	}
`;

const InviteInstruction = (props: InstructionsProps) => {
	const { t } = useTranslation();
	const { cancelInvite } = useStream();

	return (
		<InstructionsDiv>
			<InstructionsP>
				<span>{t('invite-in-progress')}</span>
				<InstructionsSpan>...</InstructionsSpan>
			</InstructionsP>
			{AgentService.getOperationWithId(IOperationName.INVITE) && AgentService.getOperationWithId(IOperationName.INVITE).initiator === AgentService.user?.clientId ? (
				<InstructionsButton type="primary" ghost className="cancel-btn-instructions" onClick={cancelInvite}>
					{t('cancel')}
				</InstructionsButton>
			) : undefined}
		</InstructionsDiv>
	);
};

export default InviteInstruction;
